<?php
/**
 * 애드페이 (AD-Pay for Gnuboard4)
 *
 * Copyright (c) 2010 Choi Jae-Young <www.miwit.com>
 *
 * 저작권 안내
 * - 저작권자는 이 프로그램을 사용하므로서 발생하는 모든 문제에 대하여 책임을 지지 않습니다. 
 * - 이 프로그램을 어떠한 형태로든 재배포 및 공개하는 것을 허락하지 않습니다.
 * - 이 저작권 표시사항을 저작권자를 제외한 그 누구도 수정할 수 없습니다.
 */

if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

$sql = "create table if not exists $pb[config_table] (
    cf_name varchar(100) not null,
    cf_auto_app char(1) not null,
    cf_payment_type varchar(5) not null default 'cash'
) $default_charset";
sql_query($sql);

$sql = "create table if not exists $pb[order_table] (
    or_id int not null auto_increment,
    pr_id int not null,
    or_app char(1) not null,
    mb_id varchar(20) not null,
    or_site varchar(255) not null,
    or_info varchar(255) not null,
    or_url varchar(255) not null,
    or_type varchar(1) not null,
    or_file varchar(255) not null,
    or_code text not null,
    or_click int unsigned not null,
    or_hit int unsigned not null,
    or_sdate date not null,
    or_edate date not null,
    or_cash int not null,
    or_point int not null,
    or_member_point int not null,
    or_target varchar(10) not null,
    or_datetime datetime not null,
    or_memo text not null,
    primary key  (or_id),
    key pb_id (pr_id,or_sdate,or_edate)
) $default_charset";
sql_query($sql);

$sql = "create table if not exists $pb[product_table] (
    pr_id int not null auto_increment,
    pr_code varchar(50) not null,
    pr_type char(1) not null,
    pr_name varchar(255) not null,
    pr_app char(1) not null,
    pr_period int not null,
    pr_reg_count int not null,
    pr_width int not null,
    pr_height int not null,
    pr_cash int not null,
    pr_point int not null,
    pr_member_point int not null,
    pr_target varchar(10) not null,
    pr_order varchar(10) not null,
    pr_default_file varchar(255) not null,
    pr_default_url varchar(255) not null,
    pr_default_code text not null,
    pr_datetime datetime not null,
    primary key  (pr_id)
) $default_charset";
sql_query($sql);

if (!$pb[cf_name])
    sql_query("insert into $pb[config_table] set cf_name = '광고등록', cf_auto_app = '1'");

sql_query("alter table $pb[config_table] add cf_payment_type varchar(5) not null default 'cash'", false);

sql_query("alter table $pb[product_table] add pr_target varchar(10) not null ", false);
sql_query("alter table $pb[product_table] add pr_point int not null after pr_cash", false);
sql_query("alter table $pb[product_table] add pr_member_point int not null after pr_point", false);
sql_query("alter table $pb[product_table] add pr_order varchar(10) not null default 'rand' after pr_target", false);

sql_query("alter table $pb[order_table] add or_target varchar(10) not null", false);
sql_query("alter table $pb[order_table] add or_point int not null after or_cash", false);
sql_query("alter table $pb[order_table] add or_member_point int not null after or_point", false);

sql_query("alter table $pb[order_table] add or_type varchar(1) not null default 'i' after or_url", false);
sql_query("alter table $pb[order_table] add or_code text not null after or_file", false);

sql_query("alter table $pb[product_table] add pr_default_code text not null", false);

